import request from "@/utils/request";
import { ElMessage } from "element-plus";
import { OrderDataResponse } from "@/types/domain/order.ts";

enum API {
  // 订单列表
  ORDER_LIST = "/order/orderInfo/auth/",
  // 订单状态
  ORDER_STATUS = "/order/orderInfo/auth/getStatusList",
}

// 订单列表
export const doGetOrderList = (
  page: number,
  limit: number,
  patientId: string,
  orderStatus: string,
) => {
  return request<OrderDataResponse>({
    url: API.ORDER_LIST + page + "/" + limit,
    method: "get",
    params: {
      patientId,
      orderStatus,
    },
  })
    .then((res) => {
      if (res.code === 200) {
        return res.data;
      }
      ElMessage.error(res.message);
      return Promise.reject(new Error(res.message));
    })
    .catch((err) => {
      return Promise.reject(new Error(err.message));
    });
};
// 订单状态
export const doGetOrderStatus = () => {
  return request<Result>({
    url: API.ORDER_STATUS,
    method: "get",
  })
    .then((res) => {
      if (res.code === 200) {
        return res.data;
      }
      ElMessage.error(res.message);
      return Promise.reject(new Error(res.message));
    })
    .catch((err) => {
      return Promise.reject(new Error(err.message));
    });
};
